package com.llmcu.source.javase.thread.producerandconsumer;

import java.util.concurrent.TimeUnit;

public class Consumer implements Runnable{
    private final Basket basket;

    public Consumer(Basket basket) {
        this.basket = basket;
    }

    @Override
    public void run() {

        while (true) {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
            // 消费者从篮子中取出一个物品
            try {
                basket.pop();
            } catch (InterruptedException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }

    }
}
